package cn.iocoder.yudao.module.infra.dal.mysql.file;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.infra.controller.admin.file.vo.file.FilePageReqVO;
import cn.iocoder.yudao.module.infra.dal.dataobject.file.FileDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 文件操作 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface FileMapper extends BaseMapperX<FileDO> {

    default PageResult<FileDO> selectPage(FilePageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<FileDO>()
                .likeIfPresent(FileDO::getPath, reqVO.getPath())
                .likeIfPresent(FileDO::getType, reqVO.getType())
                .betweenIfPresent(FileDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(FileDO::getId));
    }

    default List<FileDO> selectListByUserId(Long userId, List<String> fileType) {
        if (userId == null) {
            return null;
        }
        return selectList(new LambdaQueryWrapperX<FileDO>().eqIfPresent(FileDO::getCreator, userId)
                .inIfPresent(FileDO::getFileType, fileType));
    }


    default Integer deleteByUrls(List<String> urls) {
        return delete(new LambdaQueryWrapperX<FileDO>().in(FileDO::getUrl, urls));
    }

    default FileDO selectByUrl(String url) {
        return selectOne(new LambdaQueryWrapperX<FileDO>().eq(FileDO::getUrl, url));
    }

   
    default List<FileDO> selectHomeSwpierList() {
        String type = "0";
        return selectList(new LambdaQueryWrapperX<FileDO>().eqIfPresent(FileDO::getFileType, type));

    }
}
